<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改密码')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="layui-form" id="form-user-resetPwd" lay-filter="form-user-resetPwd" style="width: 343px;padding: 50px 68px 0 20px;margin: 0 auto;">
			<input type="hidden" name="userId" th:value="${userId}">
			<input type="hidden" name="upType" th:value="${upType}">
			<div class="layui-form-item">
				<label class="layui-form-label">旧密码：</label>
				<div class="layui-input-block">
				<input type="password" id="oldPwd" name="oldPwd" autocomplete="new-password" class="layui-input" value="">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">新密码：</label>
				<div class="layui-input-block">
				<input type="password" id="newPwd" name="newPwd" autocomplete="new-password" class="layui-input" value="">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">确认新密码：</label>
				<div class="layui-input-block">
				<input type="password" id="checkNewPwd" autocomplete="new-password" class="layui-input" value="">
				</div>
			</div>
			<div style=" margin-left: 24%; margin-top: 40px;text-align: center;">
				<button class="layui-btn layui-btn-normal" lay-submit lay-filter="btn-add">保存</button>
			</div>
		</form>
	</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
	layui.use(['laydate', 'form','layer','jquery'], function () {
		var $ = layui.$,layer = layui.layer,form = layui.form,postStr = [];
		form.on('submit(btn-add)', function(data){
			var check_arr = [{'kName':'oldPwd','kStr':'旧密码'},{'kName':'newPwd','kStr':'新密码'},{'kName':'checkNewPwd','kStr':'确认新密码'}],checkStatus = true;
			$.each(check_arr,function(i,v){
				if(!$("#"+v.kName).val()){
		            layer.msg(v.kStr+" 不能为空");
		            $("#"+v.kName).css('border','1px solid red');
		            $("#"+v.kName).focus()
		            checkStatus = false;
		            return false;
		        }
			})
	    	if($("#newPwd").val() != $("#checkNewPwd").val()){
	            layer.msg("新密码和确认新密码输入值不相同");
	            $("#checkNewPwd").css('border','1px solid red');
	            $("#checkNewPwd").focus()
	            checkStatus = false;
	            return false;
	        }
	        if(checkStatus){
	       		var url = "/system/user/editpwdpost";
	       		var data = $("#form-user-resetPwd").serialize();
	        	$.operate.post(url,data,function(result){
	        		if(result.code == 0){
	        			setTimeout(function(){
		                    window.location.reload();
		                }, 1000);
	        		}
	        	});
	        }
	        return false;
	    });
	});
</script>
</body>
</html>
